/**
 * Copyright 2009-2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。

 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 */
package chunmap.example.layer;

import java.util.List;

import javax.swing.JTextArea;

import chunmap.app.MapCtrl;
import chunmap.data.feature.Feature;
import chunmap.data.provider.LayerFactory;
import chunmap.example.BaseMap;
import chunmap.util.Function;
import chunmap.view.layer.VectorLayer;
import chunmap.view.render.GeneralSymbol;
import chunmap.view.render.LabelSymbol;
import chunmap.view.render.Style2D;
import chunmap.view.render.Symbol;

/**
 * read shapefile and show data
 * 
 * @author chunquedong
 * 
 */
public class ShapefileTest extends BaseMap {
	public static void main(String[] args) {

		ShapefileTest me = new ShapefileTest();
		me.init();
	}

	@Override
	protected void addLayer(MapCtrl map) {
		String path1=
				"D:\\ChunMap\\ChunMap1.1.1\\Data\\gs\\region.shp";
		String path2=
				"D:\\ChunMap\\ChunMap1.1.1\\Data\\gs\\city1.shp";
		String path3=
				"D:\\ChunMap\\ChunMap1.1.1\\Data\\gs\\river.shp";

		VectorLayer layer =  LayerFactory.openShapeFile(path1,1);
		layer.setDefaultStyle(new Symbol[]{new GeneralSymbol(),new LabelSymbol()});
		VectorLayer layer2 =  LayerFactory.openShapeFile(path2);
		layer2.setDefaultStyle(new Symbol[]{new GeneralSymbol(Style2D.style2())});
		VectorLayer layer3 =  LayerFactory.openShapeFile(path3);
		layer3.setDefaultStyle(new Symbol[]{new GeneralSymbol(Style2D.style1())});

		map.getLayerCollection().add(layer);
		map.getLayerCollection().add(layer2);
		map.getLayerCollection().add(layer3);
	}
	
	@Override
	protected void addButton(){
		super.addButton();
		
		final JTextArea text=new JTextArea(5,70);
		text.setLineWrap(true);
		text.setAutoscrolls(true);
		
		frame.add(text);
		
		tool.onSelectChange.add(new Function(){
			@SuppressWarnings("unchecked")
			@Override
			public Object call(Object... args) {
				List<Feature> fs=(List<Feature>)args[0];
				if(fs.size()==0){
					text.setText("");
				}else{
					text.setText(fs.get(0).toString());
				}
				return null;
			}});
	}
}
